// Time:  O(m * n)
// Space: O(1)


#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
class Solution {
public:
    vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
        if(original.size() != m * n) return {};
        
        vector<vector<int>> res;

        for(int i=0; i<original.size(); i+=n) {
            res.emplace_back(original.begin() + i, original.begin() + i + n);
        }
        return res;
    }
};

int main() {
    Solution solution;

    // Test case 1
    vector<int> original1 = {1, 2, 3, 4};
    int m1 = 2, n1 = 2;
    vector<vector<int>> expected1 = {{1, 2}, {3, 4}};
    assert(solution.construct2DArray(original1, m1, n1) == expected1);

    // Test case 2
    vector<int> original2 = {1, 2, 3};
    int m2 = 1, n2 = 3;
    vector<vector<int>> expected2 = {{1, 2, 3}};
    assert(solution.construct2DArray(original2, m2, n2) == expected2);

    // Test case 3
    vector<int> original3 = {1, 2};
    int m3 = 1, n3 = 1;
    vector<vector<int>> expected3 = {};
    assert(solution.construct2DArray(original3, m3, n3) == expected3);

    // Test case 4
    vector<int> original4 = {1, 2, 3, 4, 5, 6};
    int m4 = 2, n4 = 3;
    vector<vector<int>> expected4 = {{1, 2, 3}, {4, 5, 6}};
    assert(solution.construct2DArray(original4, m4, n4) == expected4);

    cout << "All test cases passed!" << endl;

    return 0;
}